<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 系统服务
 * Class
 * @package
 */
class Systemser extends Api
{

	protected $noNeedLogin = ['customer_servc', 'system_servc', 'customer_back_problem'];
	protected $noNeedRight = '*';

	/**
	 * 客服电话
	 */
	public function customer_servc()
	{
		$ret = \app\common\model\ServiceTels::where("servc_typs = 1 and status = 1")
			->field("id,title,mobile,landline,remark")
			->select();
		$this->success("客服电话", $ret);
	}

	/**
	 * 系统电话
	 */
	public function system_servc()
	{
		$ret = \app\common\model\ServiceTels::where("servc_typs = 2 and status = 1")
			->field("id,title,mobile,landline,remark")
			->select();
		$this->success("系统电话", $ret);
	}

	/**
	 * 客户反馈问题
	 */
	public function customer_back_problem()
	{
		$uid = $this->auth->id;
		$class_ids = $this->request->post("classId/a");
		$content = $this->request->post("content");
		if (!$class_ids && !$content) {
			$this->error(__('Invalid parameters'));
		}
		Db::startTrans();
		try {
			$flag = [];
			$con = count($class_ids);
			for ($i = 0; $i < count($class_ids); $i++) {
				$temp = [];
				$temp["uid"] = $uid;
				$temp["class_id"] = $class_ids[$i];
				$temp["remark"] = $content;
				$temp["create_time"] = time();
				$id = Db::name("question_content")->insertGetId($temp);
				if ($id) {
					array_push($flag, $id);
				}
			}
			if ($con == count($flag)) {
				Db::commit();
			} else {
				throw new \Exception("反馈失败");
			}
		} catch (\Exception $e) {
			Db::rollback();
			$this->error($e->getMessage());
		}
		$this->success("问题反馈成功", 1);
	}
}
